package com.sitech.ibnms.c3p.command.sql;

import java.util.regex.Pattern;

/**
 * Created by leo on 16/2/4.
 */
public enum SqlStatement {
    SELECT, CALL, OTHER;
    private static final Pattern PATTERN_SELECT = Pattern.compile("^\\s*SELECT\\s+", Pattern.CASE_INSENSITIVE);
    private static final Pattern PATTERN_CALL = Pattern.compile("^\\s*CALL\\s+", Pattern.CASE_INSENSITIVE);

    public static SqlStatement from(final String sql) {
        if (PATTERN_SELECT.matcher(sql).find()) return SELECT;
        if (PATTERN_CALL.matcher(sql).find()) return CALL;
        return OTHER;
    }
}
